package com.xiaolai.iodemo.Validate.core;


import com.xiaolai.iodemo.Validate.annotaction.Validate;

import java.io.File;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2015/12/18.
 */
public class ValidateHandlerScanner {

    ValidateHandlerScanner()
    {

    }

    private static List<String> getClassName(String filePath, List<String> className) {
        List<String> myClassName = new ArrayList<String>();
        File file = new File(filePath);
        File[] childFiles = file.listFiles();
        for (File childFile : childFiles) {
            if (childFile.isDirectory()) {
                myClassName.addAll(getClassName(childFile.getPath(), myClassName));
            } else {
                String childFilePath = childFile.getPath();
                childFilePath = childFilePath.substring(childFilePath.indexOf("\\classes") + 9, childFilePath.lastIndexOf("."));
                childFilePath = childFilePath.replace("\\", ".");
                myClassName.add(childFilePath);
            }
        }

        return myClassName;
    }

    /**
     * 通过注解查找有指定注解的异常处理方法
     * @param hd
     * @return
     */
    public static Method validateExceptionHandlerScanner(HandlerDefinition hd)
    {

    }


    /**
     * 通过注解上的属性查找有指定注解的类
     * @param field 属性
     * @param obj 目标对象
     * @return
     */
    public static ValidateHandler customHandlerScanner(Field field, Object obj)
    {
        if (field.isAccessible()) {
            field.setAccessible(true);
        }
        HandlerDefinition hd = field.getAnnotation(Validate.class).value();
        field.setAccessible(false);

    }

    protected static Object getMyClass(HandlerDefinition hd,String filepath,List<Class>classes) {
        List<Class> clses=new ArrayList<Class>();
        File file=new File(filepath);
        File[]clildFiles=file.listFiles();
        for(File childFile:clildFiles)
        {
            if(childFile.isDirectory())
            {
                String childFilePath=childFile.getPath();
                if (childFilePath.endsWith(".class")){

                }

            }
        }
/*   List<String> myClassName = new ArrayList<String>();
        File file = new File(filePath);
        File[] childFiles = file.listFiles();
        for (File childFile : childFiles) {
            if (childFile.isDirectory()) {
                myClassName.addAll(getClassName(childFile.getPath(), myClassName));
            } else {
                String childFilePath = childFile.getPath();
                childFilePath = childFilePath.substring(childFilePath.indexOf("\\classes") + 9, childFilePath.lastIndexOf("."));
                childFilePath = childFilePath.replace("\\", ".");
                myClassName.add(childFilePath);
            }
        }

        return myClassName;
        */

    }


}
